//
//  LHNetworkHandle.m
//  Knight_Tour
//
//  Created by 庞魁 on 15-5-16.
//  Copyright (c) 2015年 TouchOne. All rights reserved.
//

#import "LHNetworkHandle.h"
#import "AFNetworking.h"

@implementation LHNetworkHandle

+ (void)getDataWithURL:(NSString *)str completion:(void (^)(id))block
{
    // 创建AFN网络请求管理对象
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    // 设置响应解析对象
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    // 设置响应数据支持类型
    [manager.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/css",@"text/plain", nil]];
    // AFN的GET请求
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"~~~请求成功~~~");
        // 请求成功后返回的responseObject数据为NSData
        // 进行JSON解析
        id result = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        //        NSLog(@"%@", result);
        // 使用Block返回网络请求数据
        block(result);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        // 如果请求失败 返回失败信息
        NSLog(@"请求失败: %@", error);
    }];
    
    
}



@end
